package com.atguigu.service.impl;

import com.atguigu.pojo.Schedule;
import com.atguigu.service.ScheduleService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ScheduleServiceImpl implements ScheduleService {
    //准备假数据
    private static Map<Integer,Schedule> scheduleMap;
    private static int maxId = 5;

    static {

        scheduleMap = new HashMap<>();

        Schedule schedule = null;

        schedule = new Schedule(1, "学习Java", false);
        scheduleMap.put(1, schedule);

        schedule = new Schedule(2, "学习H5", true);
        scheduleMap.put(2, schedule);

        schedule = new Schedule(3, "学习Css", false);
        scheduleMap.put(3, schedule);
        schedule = new Schedule(4, "学习JavaScript", false);
        scheduleMap.put(4, schedule);

        schedule = new Schedule(5, "学习Spring", true);
        scheduleMap.put(5, schedule);

    }
    @Override
    public List<Schedule> getAll() {
        ArrayList<Schedule> list = new ArrayList<>(scheduleMap.values());
        return list;
    }

    @Override
    public void saveSchedule(Schedule schedule) {
    maxId++;
    schedule.setId(maxId);
    scheduleMap.put(maxId,schedule);
    }

    @Override
    public void updateSchedule(Schedule schedule) {
        int id = schedule.getId();
        scheduleMap.put(id,schedule);
    }

    @Override
    public void removeById(Integer id) {
       scheduleMap.remove(id);
    }
}
